home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_133 / overscan / overscan.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  7KB  |  226 lines

  1. /*
  2. (overscan.c)
  3.  
  4.    overscan
  5.   ----------
  6.  
  7.   By Ari & Dov Freund - 20/11/87
  8.  
  9. Patches up the Intuition library so that sizable windows with MaxHeight = 200
  10. (or 400 in lace), and screens with Height = 200 (or 400 in lace) will take
  11. advantage of the overscan capability of Intuition V1.2.
  12.  
  13. To install the patch: overscan
  14. To remove it:         overscan delete
  15.  
  16. Compile and assemble using Aztec C V3.4a:  cc overscan.c +C +D
  17.                                            as overscan_lib.asm
  18. Create a library file using the librarian: lb overscan.lib overscan_lib.o
  19. Link using Aztec C V3.4a:                  ln +S overscan.o overscan.lib c.lib
  20.  
  21. You may also execute the overscan.make file.
  22.  
  23. See overscan.doc for more information.
  24.  
  25. */
  26.  
  27. #undef ERROR
  28. #ifdef AZTEC_C
  29.    #ifndef _LARGE_DATA
  30.       #define ERROR
  31.    #else
  32.       #ifndef _LARGE_CODE
  33.          #define ERROR
  34.       #endif
  35.    #endif
  36.    #ifdef ERROR
  37.  
  38.    /*
  39.       If compiled with aztec and without the +C +D (large code and data)
  40.       options, generate an error to alert the user and don't compile.
  41.    */
  42.  
  43.    )Compile me with the +C +D options.
  44.    )Compile me with the +C +D options.
  45.    )Compile me with the +C +D options.
  46.    )Compile me with the +C +D options.
  47.    )Compile me with the +C +D options.
  48.    )Compile me with the +C +D options.
  49.  
  50.    #endif
  51. #endif
  52.  
  53. #ifndef ERROR
  54.  
  55. #include <libraries/dosextens.h>
  56.  
  57. #define OPENSCREEN -198L /* OpenScreen()'s vecter offset from IntuitionBase */
  58. #define OPENWINDOW -204L /* OpenWindow()'s vector offset from IntuitionBase */
  59.  
  60. main(argc,argv)
  61. int argc;
  62. char *argv[];
  63. {
  64.    /* These externals belong to overscan.lib. */
  65.    extern struct myvars{
  66.       struct MsgPort port;    /* a message port left behind for subsequent
  67.                                  invocations of overscan */
  68.       BPTR myseg;             /* pointer to segment containing the patch */
  69.       ULONG oldscreen;        /* pointer to Intuition's OpenScreen() */
  70.       ULONG oldwindow;        /* pointer to Intuition's OpenWindow() */
  71.       ULONG in_use;           /* flag indicating patch is/isn't in use */
  72.    } data;
  73.    extern UBYTE *IntuitionBase;
  74.    extern char myname[];                     /* name of message port above */
  75.    extern void screenpatch(), windowpatch(); /* See overscan_lib.asm. */
  76.  
  77.    UBYTE *OpenLibrary();
  78.    struct Process *me, *FindTask();
  79.    struct myvars *mydata, *FindPort();
  80.    ULONG *seg, *prev;                        /* pointers to my segments */
  81.    BPTR *mylast;                             /* the same */
  82.    int install, err=0;                       /* flags */
  83.    int count;                                /* count of disconnected segs */
  84.    static   char delstrng[]="delete";
  85.    char *rem=delstrng;
  86.  
  87.    printf(
  88. "\nCopyright (c) 1987, by Ari & Dov Freund.\
  89. \n\
  90. \nThis program patchs the system so that most American programs\
  91. \nwill use the extra lines on European (PAL) machines.\
  92. \nTo install patch type: \"overscan\"\
  93. \nTo delete  patch type: \"overscan delete\"\
  94. \n\
  95. \nThis program is shareware, if you like it send $5 to the authors at:\
  96. \nAri Freund\
  97. \n20 Yahalom st.\
  98. \nPetach-Tikva\
  99. \nISRAEL\n");
  100.  
  101.    /* Check for presence of "delete". */
  102.    if(argc==2)
  103.       do
  104.          if(tolower(*rem)!=tolower(*argv[1]))
  105.             err=1;
  106.       while(argv[1]++,*rem++);
  107.  
  108.    if(argc>2||err){
  109.       printf("\nUsage: %s [%s]\n",argv[0],delstrng);
  110.       return;
  111.    }
  112.  
  113.    /* Decide whether to install or remove. */
  114.    install=argc==1;
  115.  
  116.    /* Get pointer to intuition library. */
  117.    if(!(IntuitionBase=OpenLibrary("intuition.library",LIBRARY_VERSION))){
  118.       printf("\nIntuition V1.2 required\n");
  119.       return;
  120.    }
  121.  
  122.    /* Look for my message port (if found, overscan is already installed). */
  123.    mydata=FindPort(myname);
  124.  
  125.    /* If I should install but am already installed do nothing. */
  126.    if(mydata&&install){
  127.       printf("\nOverscan patch already installed.\n");
  128.       goto exit;
  129.    }
  130.    /* If I should remove but am not installed do nothing. */
  131.    else if(!install&&!mydata){
  132.       printf("\nOverscan patch already removed.\n");
  133.       goto exit;
  134.    }
  135.  
  136.    /* Get pointer to my Process structure. */
  137.    me=FindTask(NULL);
  138.  
  139.    /*
  140.       Walk through my own SegList and disconnect (if needed) the segment
  141.       containing the patch. This is done so that when I exit,
  142.       the patch will not be unloaded. The external 'data.myseg' is set as
  143.       a BPTR to this segment.
  144.    */
  145.    for(
  146.     prev=
  147.      (ULONG *)(&(*(struct CommandLineInterface *)(me->pr_CLI<<2)).cli_Module),
  148.     seg=(ULONG *)(*prev<<2),
  149.     *(mylast=&data.myseg)=NULL,
  150.     count=0
  151.    ;
  152.     seg
  153.    ;
  154.     prev=seg,
  155.     seg=(ULONG *)(*seg<<2)
  156.    )
  157.       if(       /* Should I disconnect any segments at all? */
  158.        install                                         &&
  159.                 /* Is this the segment with the patch? */
  160.        (ULONG)screenpatch<(ULONG)seg+*(seg-1)-4       &&
  161.        (ULONG)screenpatch>(ULONG)seg
  162.       ){
  163.          count++;
  164.                /* Disconnect the segment from the list */
  165.          *prev=*seg;
  166.                /* and chain it to the 'disconnected' list. */
  167.          *mylast=(BPTR)((ULONG)seg>>2);
  168.          *(mylast=(BPTR *)seg)=NULL;
  169.                /* Allow loop to continue, skiping over the disconnected seg. */
  170.          seg=prev;
  171.       }
  172.  
  173.    if(install){            /* --> Install the patch. <-- */
  174.       /*
  175.          An incorrect number of disconnected segments
  176.          means something is terribly wrong.
  177.       */
  178.       if(count!=1){
  179.          printf("\ninternal fatal error\n");
  180.          if(count>0)
  181.                            /* Reconnect the disconnected segments and exit. */
  182.             *prev=(ULONG)data.myseg;
  183.       }
  184.       else{                /* Save the old vectors and patch up Intuition. */
  185.          Forbid();
  186.          data.oldscreen=*(ULONG *)(IntuitionBase+OPENSCREEN+2);
  187.          data.oldwindow=*(ULONG *)(IntuitionBase+OPENWINDOW+2);
  188.          SetFunction(IntuitionBase,OPENSCREEN,screenpatch);
  189.          SetFunction(IntuitionBase,OPENWINDOW,windowpatch);
  190.          Permit();
  191.          /*
  192.             Link in the message port so it can be found later when we may
  193.             want to remove the patch.
  194.          */
  195.          AddPort(&data.port);
  196.          printf("\nOverscan patch installed.\n");
  197.       }
  198.    }
  199.    else{                          /* --> Remove the patch. <-- */
  200.       /*
  201.          Connect the segment used by the existing patch to myself.
  202.          This way, when I exit it will be unloaded together with me.
  203.       */
  204.       Forbid();
  205.       /* If patch is in use don't remove it. */
  206.       if(mydata->in_use){
  207.          Permit();
  208.          printf("\nOverscan patch in use, cannot remove it.\n");
  209.          goto exit;
  210.       }
  211.       *prev=(ULONG)mydata->myseg;    /* Connect the segment to myself,  */
  212.       RemPort(mydata);               /* unlink the message port,        */
  213.                                      /* and restore the vectors.        */
  214.       SetFunction(IntuitionBase,OPENSCREEN,mydata->oldscreen);
  215.       SetFunction(IntuitionBase,OPENWINDOW,mydata->oldwindow);
  216.       Permit();
  217.       printf("\nOverscan patch deleted.\n");
  218.    }
  219.  
  220.    /* Exit gracefully. */
  221. exit:
  222.    CloseLibrary(IntuitionBase);
  223. }
  224.  
  225. #endif
  226.